import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import ViewUI from 'view-design'
import i18n from '@/locale'
import config from '@/config'
import importDirective from '@/directive'
import { directive as clickOutside } from 'v-click-outside-x'
import Crypto from '@/libs/crypto'
import installPlugin from '@/plugin'
import components from '@/libs/components.js'
import moment from 'moment'
import eventBook from '@/libs/eventBook'
import Api from '@/api'
import {hasResourceAccess} from '@/libs/auth.util'
import './index.less'
import '@/assets/icons/iconfont.css'
import 'v-org-tree/dist/v-org-tree.css'

Vue.prototype.$c = new Crypto(config.aesKey)
Vue.prototype.$api = Api
Vue.use(ViewUI, {
  i18n: (key, value) => i18n.t(key, value)
})
let _i18n = window._i18n = i18n
Vue.use(components)
/**
 * @description 注册admin内置插件
 */
installPlugin(Vue)
/**
 * @description 生产环境关掉提示
 */
Vue.config.productionTip = false
/**
 * @description 全局注册应用配置
 */
Vue.prototype.$config = config
/**
 * @description MomentJS
 */
Vue.prototype.$moment = moment
/**
 * @description 全局权限查询方法
 */
Vue.prototype.$haveAuth = hasResourceAccess
/**
 * @description 页签事件通信，关闭页签tab方法
 */
Vue.prototype.$closeTab = function (route) {
  eventBook.$emit('close:tab', route || this.$route)
}
/**
 * 注册指令
 */
importDirective(Vue)
Vue.directive('clickOutside', clickOutside)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  i18n,
  store,
  render: h => h(App)
})
